package com.michaelbulava.TFS.persistence;

import com.microsoft.tfs.core.config.persistence.PersistenceStoreProvider;
import com.microsoft.tfs.core.persistence.FilesystemPersistenceStore;
import com.microsoft.tfs.core.persistence.VersionedVendorFilesystemPersistenceStore;

/**
 * Created by mbulava on 6/16/2015.
 */
public class IdeaPersistenceStoreProvider  implements PersistenceStoreProvider {
    protected static final String VENDOR_NAME = "Michael_Bulava";
    protected static final String APPLICATION_NAME = "IntelliJTFS";
    protected static final String VERSION = "1.0";
    protected static final String CACHE_CHILD_NAME = "Cache";
    protected static final String CONFIGURATION_CHILD_NAME = "Configuration";
    protected static final String LOG_CHILD_NAME = "Logs";
    private static final VersionedVendorFilesystemPersistenceStore basePersistenceStore =
            new VersionedVendorFilesystemPersistenceStore(VENDOR_NAME, APPLICATION_NAME, VERSION);
    private static final VersionedVendorFilesystemPersistenceStore cachePersistenceStore;
    private static final VersionedVendorFilesystemPersistenceStore configurationPersistenceStore;
    private static final VersionedVendorFilesystemPersistenceStore logPersistenceStore;
    public static final IdeaPersistenceStoreProvider INSTANCE;

    static {
        cachePersistenceStore = (VersionedVendorFilesystemPersistenceStore)basePersistenceStore.getChildStore(CACHE_CHILD_NAME);
        configurationPersistenceStore = (VersionedVendorFilesystemPersistenceStore)basePersistenceStore.getChildStore(CONFIGURATION_CHILD_NAME);
        logPersistenceStore = (VersionedVendorFilesystemPersistenceStore)basePersistenceStore.getChildStore(LOG_CHILD_NAME);
        INSTANCE = new IdeaPersistenceStoreProvider();
    }

    protected IdeaPersistenceStoreProvider() {
    }

    @Override
    public FilesystemPersistenceStore getCachePersistenceStore() {
        return cachePersistenceStore;
    }

    @Override
    public FilesystemPersistenceStore getConfigurationPersistenceStore() {
        return configurationPersistenceStore;
    }

    @Override
    public FilesystemPersistenceStore getLogPersistenceStore() {
        return logPersistenceStore;
    }

    @Override
    public boolean equals(Object obj){
        if(obj == this) {
            return true;
        } else if(!(obj instanceof IdeaPersistenceStoreProvider)) {
            return false;
        } else {
            IdeaPersistenceStoreProvider other = (IdeaPersistenceStoreProvider)obj;
            return this.getCachePersistenceStore().equals(other.getCachePersistenceStore()) && this.getConfigurationPersistenceStore().equals(other.getConfigurationPersistenceStore()) && this.getLogPersistenceStore().equals(other.getLogPersistenceStore());
        }
    }

    @Override
    public int hashCode(){
        byte result = 17;
        int result1 = result * 37 + this.getCachePersistenceStore().hashCode();
        result1 = result1 * 37 + this.getConfigurationPersistenceStore().hashCode();
        result1 = result1 * 37 + this.getLogPersistenceStore().hashCode();
        return result1;
    }
}
